/**
 * Copyright (C) 2011 Daniel Centore
 * 
 * This file is part of WriteIn.
 *
 * WriteIn is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * WriteIn is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with WriteIn.  If not, see <http://www.gnu.org/licenses/>.
 *  
 */
package in.write.gui;

import in.write.data.stored.PreferenceManager;

import java.awt.Frame;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

/**
 * The main window of the program
 * 
 * @author Daniel Centore
 * 
 */
public class Gui extends Frame
{
	private static final long serialVersionUID = 1L;

	private static final String X_SIZE = "X_SIZE";
	private static final String Y_SIZE = "Y_SIZE";
	private static final String MAXIMIZED = "MAXIMIZED";

	public Gui()
	{
		this.setTitle("Write-In by Daniel Centore");
		
		if (PreferenceManager.getInt(X_SIZE) > 0) // not first run
			this.setSize(PreferenceManager.getInt(X_SIZE), PreferenceManager.getInt(Y_SIZE));
		else
			this.setSize(700, 700);
		
		if (PreferenceManager.getBoolean(MAXIMIZED))
			this.setExtendedState(Frame.MAXIMIZED_BOTH);

		this.addWindowListener(new WindowListener()
		{
			@Override
			public void windowClosing(WindowEvent e)
			{
				PreferenceManager.putInt(X_SIZE, Gui.this.getWidth());
				PreferenceManager.putInt(Y_SIZE, Gui.this.getHeight());
				PreferenceManager.putBoolean(MAXIMIZED, Gui.this.getExtendedState() == Frame.MAXIMIZED_BOTH);

				System.exit(0);
			}

			@Override
			public void windowOpened(WindowEvent e)
			{
			}

			@Override
			public void windowIconified(WindowEvent e)
			{
			}

			@Override
			public void windowDeiconified(WindowEvent e)
			{
			}

			@Override
			public void windowDeactivated(WindowEvent e)
			{
			}

			@Override
			public void windowClosed(WindowEvent e)
			{
			}

			@Override
			public void windowActivated(WindowEvent e)
			{
			}
		});
	}

}
